//
//  GDImageView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/2/1.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "GDImageView.h"
#import "GDButtonView.h"
@interface GDImageView ()
@property (nonatomic, strong) UIView *imaView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *inforLabel;
@property (nonatomic, strong) GDButtonView *buttonView;
@property (nonatomic, strong) UIStackView *firstStackView;
@end

@implementation GDImageView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.imaView = [[UIView alloc]initWithFrame:CGRectZero];
    self.imaView.layer.cornerRadius = 10.0f;
    self.imaView.layer.masksToBounds = YES;
    self.imaView.backgroundColor = NormalColor;
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.text = @"You Can See Some Picture";
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont fontWithName:Helvetica size:20];
    self.titleLabel.numberOfLines = 0;
    [self.imaView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.imaView).offset(10);
        make.right.equalTo(self.imaView.mas_right).offset(-10);
    }];
    self.inforLabel = [[UILabel alloc]init];
    self.inforLabel.text = @"this can show some pictures when you click this button";
    self.inforLabel.numberOfLines = 0;
    self.inforLabel.font = [UIFont systemFontOfSize:9];
    self.inforLabel.textColor = [UIColor whiteColor];
    [self.imaView addSubview:self.inforLabel];
    [self.inforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(2);
        make.left.right.equalTo(self.titleLabel);
    }];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImaView)];
    [self.imaView addGestureRecognizer:tap];
    
    
    self.buttonView = [[GDButtonView alloc]initWithFrame:CGRectZero];
    self.buttonView.layer.cornerRadius = 10.0f;
    self.buttonView.layer.masksToBounds = YES;
    
    
    self.firstStackView = [[UIStackView alloc]initWithArrangedSubviews:@[self.imaView,self.buttonView]];
    [self addSubview:self.firstStackView];
    self.firstStackView.spacing = 5.0f;
    self.firstStackView.axis = UILayoutConstraintAxisVertical;
    self.firstStackView.distribution = UIStackViewDistributionFillEqually;
    self.firstStackView.alignment = UIStackViewAlignmentFill;
    UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
    [self.firstStackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(padding);
    }];
}

- (void)clickImaView{

    if([self.delgate respondsToSelector:@selector(showImageView)]){
        [self.delgate showImageView];
    }
    
}

@end
